local weibo_wake = GetModConfigData("weibo_wake")
if weibo_wake then
    -- 其实应该写一个统一的接口，就能做快捷键查询了
    GLOBAL.TheInput:AddKeyUpHandler(weibo_wake, function()
        if InGame() and GLOBAL.ThePlayer.prefab == "webber" then
            local whistle = GetItemFromAll("spider_whistle")
            if whistle then
                SendRPCAwithB(GLOBAL.RPC.ControllerUseItemOnSelfFromInvTile, GLOBAL.ACTIONS.HERD_FOLLOWERS, whistle)
            end
        end
    end)
end

-- 并不是按照物品栏顺序，而是优先怪物肉这样
local meat_table = {
    "cookedmonstermeat","monstermeat",
    "cookedsmallmeat","smallmeat",
    "cookedmeat","meat",
    "froglegs_cooked","froglegs",
    "fish_cooked","pondfish",
    "drumstick_cooked","drumstick",
    "bird_egg_cooked","bird_egg",
}
local function getMeat()
    for _,meat_name in pairs(meat_table)do
        local meat = GetItemFromAll(meat_name)
        if meat then
            return meat
        end
    end
    return GetItemFromAll(nil, "edible_MEAT")
end


local weibo_give = GetModConfigData("weibo_give")
if weibo_give then
    GLOBAL.TheInput:AddKeyUpHandler(weibo_give, function()
        if InGame() and GLOBAL.ThePlayer.prefab == "webber" then
            local meat = getMeat()
            if meat then
                local spiders = PlayerFindEnts(40, {"spider"})
                local target
                for _,spider in pairs(spiders)do
                    if GetLeader(spider) ~= GLOBAL.ThePlayer then
                        target = spider
                        break
                    end
                end
                if target then
                    TIP("雇佣蜘蛛", "green", "使用 "..meat.name.." 雇佣 "..target.name)
                    SendRPCAwithB(GLOBAL.RPC.ControllerUseItemOnSceneFromInvTile, GLOBAL.ACTIONS.GIVE, meat, target)
                else
                    TIP("雇佣蜘蛛", "pink", "没有可雇佣的蜘蛛")
                end
            else
                TIP("雇佣蜘蛛", "pink", "缺少食物")
            end
        end
    end)
end